//
//  SubmitOrderBottomView.m
//  Youhuiju
//
//  Created by 余尚飞 on 16/8/12.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "SubmitOrderBottomView.h"

@interface SubmitOrderBottomView ()

@property(nonatomic,strong)UILabel *addressLabel;//配送地址
@property(nonatomic,strong)UILabel *goodsCountLabel;//商品数
@property(nonatomic,strong)UILabel *allLabel;//共计
@property(nonatomic,strong)UILabel *RMBLabel;//人民币符号
@property(nonatomic,strong)UILabel *allCostLabel;//总价
@property(nonatomic,strong)UIButton *submitOrderBtn;//提交订单
@end


@implementation SubmitOrderBottomView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self creatView];
    }
    return self;
}

-(void)creatView
{
    
    UIView *background = [[UIView alloc]init];
    background.backgroundColor = [UIColor colorWithHexString:@"f5ded0"];
    [self addSubview:background];
    [background mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(0 * FitW);
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.mas_top);
        make.height.equalTo(@18);
    }];
    
    //配送地址
    self.addressLabel = [[UILabel alloc]init];
    self.addressLabel.backgroundColor = [UIColor clearColor];
    self.addressLabel.font = [UIFont systemFontOfSize:12 * FitH];
    self.addressLabel.layer.borderWidth = 1 * FitH;
    self.addressLabel.layer.borderColor = [UIColor colorWithHexString:@"f7c5c5"].CGColor;
    self.addressLabel.textColor = [UIColor colorWithHexString:@"333333"];
    self.addressLabel.text = @"送至 ：辽宁 大连市 大连开发区 华润海中国二期 四号楼一单元..........";
    [background addSubview:self.addressLabel];
    [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(background.mas_left).offset(12 * FitW);
        make.right.equalTo(background.mas_right);
        make.top.equalTo(background.mas_top);
        make.bottom.equalTo(background.mas_bottom);
//        make.edges.equalTo(background);
    }];
    
    //商品数量
    self.goodsCountLabel = [[UILabel alloc]init];
    self.goodsCountLabel.textColor = [UIColor colorWithHexString:@"999999"];
    self.goodsCountLabel.text = @"共1件商品";
    self.goodsCountLabel.font = [UIFont systemFontOfSize:12 * FitH];
    [self addSubview:self.goodsCountLabel];
    [self.goodsCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.addressLabel.mas_left);
        make.top.equalTo(background.mas_bottom).offset(8);
        make.height.equalTo(@12);
    }];
    
//共计两字
    self.allLabel = [[UILabel alloc]init];
    self.allLabel.textColor = [UIColor colorWithHexString:@"999999"];
    self.allLabel.text = @"共计";
    self.allLabel.font = [UIFont systemFontOfSize:12 * FitH];
    [self addSubview:self.allLabel];
    [self.allLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.goodsCountLabel.mas_left);
        make.top.equalTo(self.goodsCountLabel.mas_bottom).offset(8);
        make.height.equalTo(@12);
    }];
    
   //¥
    self.RMBLabel = [[UILabel alloc]init];
    self.RMBLabel.textColor = [UIColor colorWithHexString:@"ff5f7b"];
    self.RMBLabel.text = @"¥";
    self.RMBLabel.font = [UIFont systemFontOfSize:12 * FitH];
    [self addSubview:self.RMBLabel];
    [self.RMBLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.allLabel.mas_right).offset(8 * FitW);
        make.centerY.equalTo(self.allLabel.mas_centerY);
        make.height.equalTo(@12);
    }];

//总价
    self.allCostLabel = [[UILabel alloc]init];
    self.allCostLabel.textColor = [UIColor colorWithHexString:@"ff5f7b"];
    self.allCostLabel.text = @"1980.00";
    self.allCostLabel.font = [UIFont systemFontOfSize:15 * FitH];
    [self addSubview:self.allCostLabel];
    [self.allCostLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.RMBLabel.mas_right).offset(5 * FitW);
        make.centerY.equalTo(self.allLabel.mas_centerY);
        make.height.equalTo(@15);
    }];
    
//    //关键字高亮
//    NSString *result = @"1980.00";
//    NSString *keyWords = @"00";
//    //关键字标红效果
//    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:result];
//    //获取关键字属性
//    NSRange rang = [result rangeOfString:keyWords];
//    //设置关键字属性
//    [attributeString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:12 * FitH],NSFontAttributeName, nil] range:rang];
//    //添加到label
//    self.allCostLabel.attributedText = attributeString;
    
    
    //提交订单
    self.submitOrderBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.submitOrderBtn.backgroundColor = [UIColor colorWithHexString:@"ff5f7b"];
    [self.submitOrderBtn setTitle:@"提交订单" forState:UIControlStateNormal];
    self.submitOrderBtn.tintColor = [UIColor whiteColor];
    [self.submitOrderBtn addTarget:self action:@selector(buttonClickedAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.submitOrderBtn];
    [self.submitOrderBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(background.mas_bottom);
        make.right.equalTo(self.mas_right);
        make.size.mas_equalTo(CGSizeMake(149 *FitW, 49));
        
    }];
    
}

-(void)setAllCost:(NSInteger)allCost
{
    if (_allCost != allCost)
    {
        _allCost = allCost;
        
        //关键字高亮
        NSString *result = [NSString stringWithFormat:@"%zd.00",_allCost];
        NSString *keyWords = @".00";
        //关键字标红效果
        NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc]initWithString:result];
        //获取关键字属性
        NSRange rang = [result rangeOfString:keyWords];
        //设置关键字属性
        [attributeString setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:12 * FitH],NSFontAttributeName, nil] range:rang];
        //添加到label
        self.allCostLabel.attributedText = attributeString;
    }
}

-(void)setGoodNum:(NSInteger)goodNum
{
    if (_goodNum != goodNum)
    {
        _goodNum = goodNum;
        
        self.goodsCountLabel.text = [NSString stringWithFormat: @"共%zd件商品",_goodNum];
    }
}


-(void)buttonClickedAction:(UIButton *)sender
{
    if (self.buttonClickedHandler)
    {
        self.buttonClickedHandler();
    }
}

@end
